const { createClient } = require('redis')
//默认 链接localhost 6379
const express = require('express')
const geoip = require('geoip-lite');
const app = express()
const port = 2521
const client = createClient();
client.connect()
client.on('error', err => console.log('redis链接失败', err));
client.on('connect',()=>{
    console.log('redis链接成功')
})




app.get('/',(req,res)=>{
    const ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
    console.log(ip)
    const lookup = geoip.lookup(ip);
   
    if (lookup) {
      const { latitude, longitude } = lookup;
      res.send(`当前IP地址的经纬度是: 纬度 ${latitude}, 经度 ${longitude}`);
    } else {
      res.send('无法获取经纬度信息。');
    }
})

app.post('/loaction',(req,res)=>{

})




app.listen(port,()=>{
    console.log('开启监听' + port + '监听')
})













